﻿//Include("Mz");

/**
 * @fileoverview 创建一个整串的namespace
 * @author meizz
 * @version 20090426
 *
 * @name Mz.namespace
 * @namespace Mz.namespace
 * @param {String} str namespace字符串
 * @param {Object} owner 该命名空间的宿主
 * @return {Object} 返回生成的最长串命名空间对象或空（字符串不符合命名规范）
 */
Mz.namespace = function(str, owner) {
    if (/^(\.[\w\$][\w\-\$]*)+$/.test("." + str)) {
        owner = typeof owner == "function" ||
                typeof owner == "object" ? owner || window : window;

        for (var e, a = str.split("."), i = 0; i < a.length; i++) {
            e = owner[a[i]];
            if (!e || !(typeof e == "object" || typeof e == "function")) {
                owner[a[i]] = {};
            }
            owner = owner[a[i]];
        }
        return owner;
    }
    return null;
};

Mz.ns = Mz.namespace;